
package com.android.JiYclock;

import com.android.JiYclocks.SpecialAlarms;

import android.content.Context;
import android.content.Intent;
import android.content.BroadcastReceiver;

public class AlarmInitReceiver extends BroadcastReceiver {

    /**
     * 当遇到系统启动
     * Sets alarm on ACTION_BOOT_COMPLETED.  Resets alarm on
     * TIME_SET, TIMEZONE_CHANGED
     */
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (Log.LOGV) Log.v("AlarmInitReceiver" + action);

        if (context.getContentResolver() == null) {
            Log.e("AlarmInitReceiver: FAILURE unable to get content resolver.  Alarms inactive.");
            return;
        }
        //如果检测到重启，那就加载距离当前最近的一个闹钟
        if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
        	//暂时考虑Alarms,下一步需要考虑SpecialAlarms
            Alarms.saveSnoozeAlert(context, -1, -1);
            
            SpecialAlarms.saveSnoozeAlert(context, -1, -1);
            
            Alarms.disableExpiredAlarms(context);
            
            SpecialAlarms.disableExpiredAlarms(context);
            Log.v("ACTION_BOOT_COMPLETED\t"+Intent.ACTION_BOOT_COMPLETED);
        }
        Alarms.setNextAlert(context);
        SpecialAlarms .setNextAlert(context);
    }
}
